import { createRouter, createWebHistory } from 'vue-router'
import { routes } from './routes'
import EventEmitter from '@u/EventEmitter'

const router = createRouter({
  history: createWebHistory(),
  routes
})

EventEmitter.on('API_ERROR', (response) => {
  router.push('/notFound')
})
EventEmitter.on('API:UN_AUTH', () => {
  router.push('/login')
})
router.beforeEach((to, from, next) => {
  next()
})

export default router